/* AXIOS的二次配置 */
import axios from "axios";
import qs from 'qs';
import utils from '@/assets/utils';

// axios.defaults.baseURL = "";
// axios.defaults.timeout = 10000;
// axios.defaults.withCredentials = true;
axios.defaults.transformRequest = data => {
    if (utils.isPlainObject(data)) data = qs.stringify(data);
    return data;
};

axios.interceptors.request.use(config => {
    return config;
});

axios.interceptors.response.use(response => {
    return response.data;
}, reason => {
    if (reason && reason.response) {
        // HTTP状态码错误
        let status = reason.response.status;
        switch (status) {
            case 400:
                // ...
                break;
        }
    } else {
        // 请求中断或者断网

    }
    return Promise.reject(reason);
});

export default axios;